home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-06-28 | 2.9 KB | 141 lines | [TEXT/CWIE] |
- // StringView.cp
-
- #ifndef StringView_h
- #include "StringView.h"
- #endif
- #ifndef ViewMap_h
- #include "ViewMap.h"
- #endif
- #ifndef Justification_h
- #include "Justification.h"
- #endif
- #ifndef ForegroundColorMaintainer_h
- #include "ForegroundColorMaintainer.h"
- #endif
- #ifndef BackgroundColorMaintainer_h
- #include "BackgroundColorMaintainer.h"
- #endif
- #ifndef FaceMaintainer_h
- #include "FaceMaintainer.h"
- #endif
- #ifndef TextModeMaintainer_h
- #include "TextModeMaintainer.h"
- #endif
- #ifndef IntegerFaceMetrics_h
- #include "IntegerFaceMetrics.h"
- #endif
- #ifndef TemporaryPort_h
- #include "TemporaryPort.h"
- #endif
-
- StringView::StringView( ::Face face )
- : HasFace( face ),
- HasVerticalJustification( Justification::Center() ),
- HasHorizontalJustification( Justification::Leading() )
- {
- }
-
- void StringView::Draw( const ViewMap& map ) const
- {
- ForegroundColorMaintainer foreground( ForegroundColor() );
- BackgroundColorMaintainer background( BackgroundColor() );
- FaceMaintainer face( Face() );
- TextModeMaintainer mode( SourceMode::srcCopy );
-
- Rectangle exterior( map.Bounds() );
- Rectangle interior( exterior );
-
- IntegerFaceMetrics metrics( IntegerFaceMetrics::Current() );
-
- uint32 width = StringWidth( string );
- HorizontalJustification().InsetWidth( interior, width );
- VerticalJustification().InsetHeight( interior, metrics.UnleadedHeight() );
-
- if ( string.Length() > 0 )
- {
- MoveTo( interior.left, interior.bottom - metrics.Descent() );
- DrawJustified( reinterpret_cast<int8 *>( const_cast<uint8*>( &string[0] ) ),
- string.Length(),
- Fixed(interior.Width() - width ) << 16,
- smOnlyStyleRun,
- PointObject(1,1), PointObject(1,1) );
- }
-
- Rectangle right( exterior );
- right.left = map.Port().PenPosition().h;
- EraseRect( &right );
-
- Rectangle top( exterior );
- top.bottom = interior.top;
- EraseRect( &top );
-
- Rectangle bottom( exterior );
- bottom.top = interior.bottom;
- EraseRect( &bottom );
-
- Rectangle left( exterior );
- left.right = interior.left;
- EraseRect( &left );
- }
-
- void StringView::SetString( ConstPString newString )
- {
- if ( string == newString )
- return;
-
- string = newString;
- Invalidate();
- }
-
- void StringView::ForegroundColorChanged()
- {
- Invalidate();
- }
-
- void StringView::BackgroundColorChanged()
- {
- Invalidate();
- }
-
- void StringView::FaceChanged()
- {
- Invalidate();
- }
-
- void StringView::VerticalJustificationChanged()
- {
- Invalidate();
- }
-
- void StringView::HorizontalJustificationChanged()
- {
- Invalidate();
- }
-
- uint16 StringView::MinimumHeight() const
- {
- return IntegerFaceMetrics( Face() ).UnleadedHeight();
- }
-
- uint16 StringView::ReasonableWidth() const
- {
- return 48;
- }
-
- uint16 StringView::BestWidth() const
- {
- return WidthOf( string );
- }
-
- uint16 StringView::BestHeight() const
- {
- return MinimumHeight();
- }
-
- uint16 StringView::WidthOf( ConstPString s ) const
- {
- TemporaryPort port;
- port.Port().SetFace( Face() );
- return StringWidth( s );
- }
-